package com.maxd.controller.pdd;

import com.maxd.error.Result;
import com.maxd.error.ResultUtil;
import com.maxd.model.CommonInfo;
import com.maxd.model.UserInfo;
import com.maxd.respository.common.CommonRepository;
import com.maxd.respository.userinfo.UserRepository;
import com.maxd.utils.Config;
import com.pdd.pop.sdk.http.PopBaseHttpResponse;
import com.pdd.pop.sdk.http.PopClient;
import com.pdd.pop.sdk.http.PopHttpClient;
import com.pdd.pop.sdk.http.api.pop.request.*;
import com.pdd.pop.sdk.http.api.pop.response.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import weixin.popular.util.JsonUtil;

import java.util.ArrayList;
import java.util.List;

@RestController
@Api(value = "拼多多API管理", tags = {"拼多多API管理"})
@RequestMapping(value = "/pdd")
public class PddController {
    @Autowired
    private CommonRepository commonRepository;
    @Autowired
    private UserRepository userRepository;

    /**
     * 排序方式:
     * 0-综合排序;
     * 1-按佣金比率升序;
     * 2-按佣金比例降序;
     * 3-按价格升序;
     * 4-按价格降序;
     * 5-按销量升序;
     * 6-按销量降序;
     * 7-优惠券金额排序升序;
     * -优惠券金额排序降序;
     * 9-券后价升序排序;
     * 10-券后价降序排序;
     * 11-按照加入多多进宝时间升序;
     * 12-按照加入多多进宝时间降序;
     * 13-按佣金金额升序排序;
     * 14-按佣金金额降序排序;
     * 15-店铺描述评分升序;
     * 16-店铺描述评分降序;
     * 17-店铺物流评分升序;
     * 18-店铺物流评分降序;
     * 19-店铺服务评分升序;
     * 20-店铺服务评分降序;
     * 27-描述评分击败同类店铺百分比升序，
     * 28-描述评分击败同类店铺百分比降序，
     * 29-物流评分击败同类店铺百分比升序，
     * 30-物流评分击败同类店铺百分比降序，
     * 31-服务评分击败同类店铺百分比升序，
     * 32-服务评分击败同类店铺百分比降序
     */
    @GetMapping("/list/sortType/{sortType:.+}/page/{page:.+}/pageSize/{pageSize:.+}")
    @ApiOperation("商品数据筛选通过筛选sort_type分页")
    public PddDdkGoodsSearchResponse getGoodsBySortType(@PathVariable Integer sortType,
           @PathVariable Integer page, @PathVariable Integer pageSize) {
        PddDdkGoodsSearchResponse response = null;
        try {
            //clientId
            CommonInfo clientId = commonRepository.findOne(23);
            CommonInfo clientSecret = commonRepository.findOne(24);
            PopClient client = new PopHttpClient(clientId.getValue() != null ? clientId.getValue() : Config.clientId, clientSecret.getValue() != null ? clientSecret.getValue() : Config.clientSecret);
            PddDdkGoodsSearchRequest request = new PddDdkGoodsSearchRequest();
            request.setPage(page);
            CommonInfo pdd = commonRepository.findOne(26);
            UserInfo userInfo = userRepository.getUserByPdd(pdd.getValue());
            String s1 = "{\"uid\":\"" + userInfo.getRelationId() + "\"}";
            request.setPid(userInfo.getPdd());
            request.setCustomParameters(s1);
            request.setPageSize(pageSize);
            request.setSortType(sortType);
            request.setWithCoupon(false);
            return client.syncInvoke(request);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @GetMapping("/list/keyword/{sortType:.+}/page/{page:.+}/pageSize/{pageSize:.+}")
    @ApiOperation("商品数据筛选通过筛选sort_type分页")
    public PddDdkGoodsSearchResponse getGoodsBySortTypeAndKeyword(@RequestParam(required = false) String pid, @RequestParam String keyword, @PathVariable Integer sortType, @PathVariable Integer page, @PathVariable Integer pageSize) {
        PddDdkGoodsSearchResponse response = null;
        try {
            CommonInfo clientId = commonRepository.findOne(23);
            CommonInfo clientSecret = commonRepository.findOne(24);
            PopClient client = new PopHttpClient(clientId.getValue() != null ? clientId.getValue() : Config.clientId, clientSecret.getValue() != null ? clientSecret.getValue() : Config.clientSecret);
            PddDdkGoodsSearchRequest request = new PddDdkGoodsSearchRequest();

            if (keyword != null) {
                request.setKeyword(keyword);
            }
            UserInfo userInfo;
            if (StringUtils.isNotEmpty(pid)) {
                userInfo = userRepository.getUserByPdd(pid);
                String s = "{\"uid\":\"" + userInfo.getRelationId() + "\"}";
                PddDdkMemberAuthorityQueryRequest request1 = new PddDdkMemberAuthorityQueryRequest();
                request1.setPid(userInfo.getPdd());
                request1.setCustomParameters(s);
                PddDdkMemberAuthorityQueryResponse response1 = client.syncInvoke(request1);
                System.out.println(JsonUtil.toJSONString(response1));
                if (response1.getAuthorityQueryResponse().getBind() == 0) {
                    CommonInfo pdd = commonRepository.findOne(26);
                    userInfo = userRepository.getUserByPdd(pdd.getValue());
                    String s1 = "{\"uid\":\"" + userInfo.getRelationId() + "\"}";
                    request.setPid(userInfo.getPdd());
                    request.setCustomParameters(s1);
                } else {
                    request.setPid(userInfo.getPdd());
                    request.setCustomParameters(s);
                }
            } else {
                //没有pid的时候
                CommonInfo pdd = commonRepository.findOne(26);
                userInfo = userRepository.getUserByPdd(pdd.getValue());
                String s = "{\"uid\":\"" + userInfo.getRelationId() + "\"}";
                request.setPid(userInfo.getPdd());
                request.setCustomParameters(s);
            }


            request.setPage(page);
            request.setPageSize(pageSize);
            request.setSortType(sortType);
            request.setWithCoupon(false);
            return client.syncInvoke(request);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @GetMapping("/details/{id:.+}")
    @ApiOperation("通过产品id获取商品详情")
    public PddDdkGoodsDetailResponse getPddDdkGoodsDetailById(@PathVariable String id) {
        try {
            CommonInfo clientId = commonRepository.findOne(23);
            CommonInfo clientSecret = commonRepository.findOne(24);
            PopClient client = new PopHttpClient(clientId.getValue() != null ? clientId.getValue() : Config.clientId, clientSecret.getValue() != null ? clientSecret.getValue() : Config.clientSecret);
            PddDdkGoodsSearchRequest request = new PddDdkGoodsSearchRequest();
            request.setKeyword(id);
            CommonInfo pdd = commonRepository.findOne(26);
            UserInfo userInfo = userRepository.getUserByPdd(pdd.getValue());
            String s1 = "{\"uid\":\"" + userInfo.getRelationId() + "\"}";
            request.setPid(userInfo.getPdd());
            request.setCustomParameters(s1);
            request.setWithCoupon(false);
            PddDdkGoodsSearchResponse pddDdkGoodsSearchResponse = client.syncInvoke(request);
            String goodsSign = pddDdkGoodsSearchResponse.getGoodsSearchResponse().getGoodsList().get(0).getGoodsSign();
            PddDdkGoodsDetailRequest request1= new PddDdkGoodsDetailRequest();
            request1.setGoodsSign(goodsSign);
            /*List<Long> goodsIdList = new ArrayList<Long>();
            goodsIdList.add(id);
            goodsIdList
            request.setGoodsIdList(goodsIdList);*/
            return client.syncInvoke(request1);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /*@GetMapping("/theme/list/{page:.+}/pageSize/{pageSize:.+}")
    @ApiOperation("（多多进宝主题列表查询）")
    public PddDdkThemeListGetResponse getTheme(@PathVariable Integer page, @PathVariable Integer pageSize) {
        try {
            CommonInfo clientId = commonRepository.findOne(23);
            CommonInfo clientSecret = commonRepository.findOne(24);
            PopClient client = new PopHttpClient(clientId.getValue() != null ? clientId.getValue() : Config.clientId, clientSecret.getValue() != null ? clientSecret.getValue() : Config.clientSecret);

            PddDdkThemeListGetRequest request = new PddDdkThemeListGetRequest();
            request.setPageSize(pageSize);
            request.setPage(page);
            return client.syncInvoke(request);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }*/

    /*@GetMapping("/theme/{id:.+}")
    @ApiOperation("（多多进宝主题商品查询）")
    public PddDdkThemeGoodsSearchResponse getTheme(@PathVariable Long id) {
        try {
            CommonInfo clientId = commonRepository.findOne(23);
            CommonInfo clientSecret = commonRepository.findOne(24);
            PopClient client = new PopHttpClient(clientId.getValue() != null ? clientId.getValue() : Config.clientId, clientSecret.getValue() != null ? clientSecret.getValue() : Config.clientSecret);

            PddDdkThemeGoodsSearchRequest request = new PddDdkThemeGoodsSearchRequest();
            request.setThemeId(id);
            return client.syncInvoke(request);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }*/

    /**
     * @param sortType 1-实时热销榜；2-实时收益榜
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/query/sortType/{sortType:.+}/page/{page:.+}/pageSize/{pageSize:.+}")
    @ApiOperation("多多客获取爆款排行商品接口")
    public com.maxd.utils.pdd.PddDdkTopGoodsListQueryResponse getGoodsByHot(@PathVariable Integer sortType, @PathVariable Integer page, @PathVariable Integer pageSize) {
        try {
            CommonInfo clientId = commonRepository.findOne(23);
            CommonInfo clientSecret = commonRepository.findOne(24);
            PopClient client = new PopHttpClient(clientId.getValue() != null ? clientId.getValue() : Config.clientId, clientSecret.getValue() != null ? clientSecret.getValue() : Config.clientSecret);
            //pdd.ddk.goods.recommend.get
            PddDdkGoodsRecommendGetRequest request = new PddDdkGoodsRecommendGetRequest();
            com.maxd.utils.pdd.PddDdkTopGoodsListQueryResponse pddDdkTopGoodsListQueryResponse1=new com.maxd.utils.pdd.PddDdkTopGoodsListQueryResponse();
            com.maxd.utils.pdd.PddDdkTopGoodsListQueryResponse.TopGoodsListGetResponse topGoodsListGetResponse=new com.maxd.utils.pdd.PddDdkTopGoodsListQueryResponse.TopGoodsListGetResponse();
            List<com.maxd.utils.pdd.PddDdkTopGoodsListQueryResponse.TopGoodsListGetResponseListItem> topGoodsListGetResponseListItems = new ArrayList<>();
            topGoodsListGetResponse.setList(topGoodsListGetResponseListItems);
            pddDdkTopGoodsListQueryResponse1.setTopGoodsListGetResponse(topGoodsListGetResponse);
            request.setOffset(page * pageSize);
            //request.setSortType(sortType);
            //5 实时热销榜  6 实时收益榜
            request.setChannelType(sortType+4);
            request.setLimit(pageSize);
            PddDdkGoodsRecommendGetResponse pddDdkGoodsRecommendGetResponse = client.syncInvoke(request);
            List<PddDdkGoodsRecommendGetResponse.GoodsBasicDetailResponseListItem> list = pddDdkGoodsRecommendGetResponse.getGoodsBasicDetailResponse().getList();
            List<com.maxd.utils.pdd.PddDdkTopGoodsListQueryResponse.TopGoodsListGetResponseListItem> list2=pddDdkTopGoodsListQueryResponse1.getTopGoodsListGetResponse().getList();
            for(PddDdkGoodsRecommendGetResponse.GoodsBasicDetailResponseListItem item:list){
                com.maxd.utils.pdd.PddDdkTopGoodsListQueryResponse.TopGoodsListGetResponseListItem i=new com.maxd.utils.pdd.PddDdkTopGoodsListQueryResponse.TopGoodsListGetResponseListItem();
                i.setCatIds(item.getCatIds());
                i.setCouponDiscount(item.getCouponDiscount());
                i.setCouponEndTime(item.getCouponEndTime());
                i.setCouponMinOrderAmount(item.getCouponMinOrderAmount());
                i.setCouponRemainQuantity(item.getCouponRemainQuantity());
                i.setCouponTotalQuantity(item.getCouponTotalQuantity());
                i.setCouponStartTime(item.getCouponStartTime());
                i.setDescTxt(item.getDescTxt());
                i.setGoodsDesc(item.getGoodsDesc());
                List<String> list1=new ArrayList<>();
                list1.add(item.getGoodsGalleryUrls());
                i.setGoodsGalleryUrls(list1);
                i.setGoodsId(item.getGoodsId());
                i.setGoodsImageUrl(item.getGoodsImageUrl());
                i.setGoodsName(item.getGoodsName());
                i.setGoodsSign(item.getGoodsSign());
                i.setGoodsThumbnailUrl(item.getGoodsThumbnailUrl());
                i.setLgstTxt(item.getLgstTxt());
                i.setMallId(item.getMallId());
                i.setOptName(item.getOptName());
                i.setMallName(item.getMallName());
                i.setMinGroupPrice(item.getMinGroupPrice());
                i.setMinNormalPrice(item.getMinNormalPrice());
                i.setOptId(Long.parseLong(item.getOptId()));
                i.setOptIds(item.getOptIds());
                i.setPredictPromotionRate(item.getPredictPromotionRate());
                i.setPromotionRate(item.getPromotionRate());
                i.setSalesTip(item.getSalesTip());
                i.setSearchId(item.getSearchId());
                i.setServTxt(item.getServTxt());
                list2.add(i);
            }
            pddDdkTopGoodsListQueryResponse1.setRequestId(pddDdkGoodsRecommendGetResponse.getRequestId());
            PopBaseHttpResponse.ErrorResponse errorResponse = pddDdkGoodsRecommendGetResponse.getErrorResponse();
            com.maxd.utils.pdd.PopBaseHttpResponse.ErrorResponse errorResponse1 = new com.maxd.utils.pdd.PopBaseHttpResponse.ErrorResponse();
            pddDdkTopGoodsListQueryResponse1.setErrorResponse(errorResponse1);
            if(errorResponse!=null){
                pddDdkTopGoodsListQueryResponse1.getErrorResponse().setErrorCode(errorResponse.getErrorCode());
                pddDdkTopGoodsListQueryResponse1.getErrorResponse().setErrorMsg(errorResponse.getErrorMsg());
                pddDdkTopGoodsListQueryResponse1.getErrorResponse().setRequestId(errorResponse.getRequestId());
                pddDdkTopGoodsListQueryResponse1.getErrorResponse().setSubMsg(errorResponse.getSubMsg());
                pddDdkTopGoodsListQueryResponse1.getErrorResponse().setSubCode(errorResponse.getSubCode());
            }
            com.maxd.utils.pdd.PddDdkTopGoodsListQueryResponse.TopGoodsListGetResponse topGoodsListGetResponse1 = pddDdkTopGoodsListQueryResponse1.getTopGoodsListGetResponse();
            topGoodsListGetResponse1.setTotal(pddDdkGoodsRecommendGetResponse.getGoodsBasicDetailResponse().getTotal());
            topGoodsListGetResponse1.setSearchId(pddDdkGoodsRecommendGetResponse.getGoodsBasicDetailResponse().getSearchId());
            topGoodsListGetResponse1.setListId(pddDdkGoodsRecommendGetResponse.getGoodsBasicDetailResponse().getListId());
            return pddDdkTopGoodsListQueryResponse1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }



   /* @GetMapping("/qrcode/{pid:.+}/{itemid:.+}")
    @ApiOperation("（多多客生成单品推广小程序二维码url）")
    public PddDdkWeappQrcodeUrlGenResponse getQrcode(@PathVariable String pid, @PathVariable Long itemid) {
        try {
            CommonInfo clientId = commonRepository.findOne(23);
            CommonInfo clientSecret = commonRepository.findOne(24);
            PopClient client = new PopHttpClient(clientId.getValue() != null ? clientId.getValue() : Config.clientId, clientSecret.getValue() != null ? clientSecret.getValue() : Config.clientSecret);

            PddDdkWeappQrcodeUrlGenRequest request = new PddDdkWeappQrcodeUrlGenRequest();
            request.setPId(pid);
            List<Long> goodsIdList = new ArrayList<Long>();
            goodsIdList.add(itemid);
            request.setGoodsIdList(goodsIdList);
            return client.syncInvoke(request);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }*/


    @GetMapping("/promotion")
    @ApiOperation("多多进宝推广链接生成）")
    public PddDdkGoodsPromotionUrlGenerateResponse getUrlInfo(@RequestParam String pid, @RequestParam String goodId, @RequestParam boolean webApp) {
        try {
            CommonInfo clientId = commonRepository.findOne(23);
            CommonInfo clientSecret = commonRepository.findOne(24);
            if(StringUtils.isEmpty(pid)){
                pid=commonRepository.findOne(26).getValue();
            }
            UserInfo userInfo = userRepository.getUserByPdd(pid);
            PopClient client = new PopHttpClient(clientId.getValue() != null ? clientId.getValue() : Config.clientId, clientSecret.getValue() != null ? clientSecret.getValue() : Config.clientSecret);

            String s = "{\"uid\":\"" + userInfo.getRelationId() + "\"}";
            PddDdkMemberAuthorityQueryRequest request1 = new PddDdkMemberAuthorityQueryRequest();
            request1.setPid(userInfo.getPdd());
            request1.setCustomParameters(s);
            PddDdkMemberAuthorityQueryResponse response1 = client.syncInvoke(request1);
            System.out.println(JsonUtil.toJSONString(response1));

            if (response1.getAuthorityQueryResponse().getBind() == 0) {
                CommonInfo pdd = commonRepository.findOne(26);
                UserInfo userInfos = userRepository.getUserByPdd(pdd.getValue());
                PddDdkGoodsSearchRequest requests = new PddDdkGoodsSearchRequest();
                requests.setKeyword(goodId);
                String s1 = "{\"uid\":\"" + userInfos.getRelationId() + "\"}";
                requests.setPid(userInfos.getPdd());
                requests.setCustomParameters(s1);
                requests.setWithCoupon(false);
                PddDdkGoodsSearchResponse pddDdkGoodsSearchResponse = client.syncInvoke(requests);
                String goodsSign = pddDdkGoodsSearchResponse.getGoodsSearchResponse().getGoodsList().get(0).getGoodsSign();
                PddDdkGoodsPromotionUrlGenerateRequest request = new PddDdkGoodsPromotionUrlGenerateRequest();
                request.setPId(pid);
                String s6 = "{\"uid\":\"" + userInfo.getRelationId() + "\"}";
                request.setCustomParameters(s6);
                request.setGenerateAuthorityUrl(true);
                request.setGoodsSign(goodsSign);
                request.setGenerateShortUrl(true);
                request.setMultiGroup(false);
                request.setGenerateWeApp(webApp);
                System.out.println(JsonUtil.toJSONString(request));
                return client.syncInvoke(request);
            }else{
                PddDdkGoodsSearchRequest requests = new PddDdkGoodsSearchRequest();
                requests.setKeyword(goodId);
                String s1 = "{\"uid\":\"" + userInfo.getRelationId() + "\"}";
                requests.setPid(userInfo.getPdd());
                requests.setCustomParameters(s1);
                requests.setWithCoupon(false);
                PddDdkGoodsSearchResponse pddDdkGoodsSearchResponse = client.syncInvoke(requests);
                String goodsSign = pddDdkGoodsSearchResponse.getGoodsSearchResponse().getGoodsList().get(0).getGoodsSign();
                PddDdkGoodsPromotionUrlGenerateRequest request = new PddDdkGoodsPromotionUrlGenerateRequest();
                request.setPId(pid);
                String s6 = "{\"uid\":\"" + userInfo.getRelationId() + "\"}";
                request.setCustomParameters(s6);
                request.setGoodsSign(goodsSign);
                request.setGenerateShortUrl(true);
                request.setMultiGroup(false);
                request.setGenerateWeApp(webApp);
                System.out.println(JsonUtil.toJSONString(request));
                return client.syncInvoke(request);
            }



        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @GetMapping("/bijia")
    @ApiOperation("多多进宝比价备案")
    @ResponseBody
    public Result getUrlInfo(@RequestParam Long userId) {
        UserInfo userInfo = userRepository.getUserById(userId);

        if (userInfo.getPdd() != null) {
            try {
                CommonInfo clientId = commonRepository.findOne(23);
                CommonInfo clientSecret = commonRepository.findOne(24);
                PopClient client = new PopHttpClient(clientId.getValue() != null ? clientId.getValue() : Config.clientId, clientSecret.getValue() != null ? clientSecret.getValue() : Config.clientSecret);
                //检查备案

                PddDdkMemberAuthorityQueryRequest request = new PddDdkMemberAuthorityQueryRequest();
                request.setPid(userInfo.getPdd());
                String s = "{\"uid\":\"" + userInfo.getRelationId() + "\"}";
                request.setCustomParameters(s);

                PddDdkMemberAuthorityQueryResponse response = client.syncInvoke(request);
                System.out.println(JsonUtil.toJSONString(response));

                if (response != null) {
                    //0表示未备案
                    if (response.getAuthorityQueryResponse().getBind() == 0) {
                        //去备案
                        PddDdkRpPromUrlGenerateRequest request1 = new PddDdkRpPromUrlGenerateRequest();
                        request1.setChannelType(10);
                        request1.setCustomParameters(s);
                        List<String> pIdList = new ArrayList<>();
                        pIdList.add(userInfo.getPdd());
                        request1.setPIdList(pIdList);
                        PddDdkRpPromUrlGenerateResponse response1 = client.syncInvoke(request1);
                        System.out.println(JsonUtil.toJSONString(response1));
                        return ResultUtil.success(response1.getRpPromotionUrlGenerateResponse().getUrlList());
                    } else {
                        return ResultUtil.error(9999,"该账号已经备案过了！");
                    }
                }

            } catch (Exception e) {
                e.printStackTrace();

            }

        }
        return ResultUtil.error(9999,"网络请求出错！");
    }


    /**
     * 拼多多 多多进宝 商品推荐API
     */
    @GetMapping("/getRecommendProd")
    @ApiOperation("（多多进宝商品推荐API）")
    public PddDdkGoodsRecommendGetResponse getRecommendProd(@RequestParam String pid,
               @RequestParam String listId,@RequestParam Integer page, @RequestParam Integer size,
               @RequestParam Integer channelType,@RequestParam Long catId) {
        //clientId
        CommonInfo clientId = commonRepository.findOne(23);
        CommonInfo clientSecret = commonRepository.findOne(24);
        PopClient client = new PopHttpClient(clientId.getValue() != null ? clientId.getValue() : Config.clientId, clientSecret.getValue() != null ? clientSecret.getValue() : Config.clientSecret);

        PddDdkGoodsRecommendGetRequest request = new PddDdkGoodsRecommendGetRequest();
        //0-1.9包邮, 1-今日爆款, 2-品牌清仓,3-相似商品推荐,4-猜你喜欢,5-实时热销,6-实时收益,7-今日畅销,8-高佣榜单，默认1
        if("".equals(pid)||pid==null){
            request.setPid(pid);
        }else {
            request.setPid(pid);
        }
        request.setChannelType(channelType);
        request.setCustomParameters(null);
        request.setLimit(page);
        request.setListId(listId);
        request.setOffset(size);
        request.setCatId(catId);
        List<Long> goodsIds = new ArrayList<Long>();
//        goodsIds.add(0L);
        request.setGoodsIds(goodsIds);
        PddDdkGoodsRecommendGetResponse response = null;
        try {
            response = client.syncInvoke(request);
            //System.out.println(JsonUtil.transferToJson(response));
        } catch (Exception e) {
            e.printStackTrace();
        }


        return response;
    }


    @GetMapping("/getGeneratePromUrl")
    @ApiOperation("（生成商城-频道推广链接）")
    //4-限时秒杀,39997-充值中心, 39998-转链type，39996-百亿补贴，40000-领券中心
    public PddDdkResourceUrlGenResponse getGeneratePromUrl(@RequestParam String pid) {
        //	0, "1.9包邮"；1, "今日爆款"； 2, "品牌清仓"； 4,"PC端专属商城"；不传值为默认商城
        CommonInfo clientId = commonRepository.findOne(23);
        CommonInfo clientSecret = commonRepository.findOne(24);
        PopClient client = new PopHttpClient(clientId.getValue() != null ? clientId.getValue() : Config.clientId, clientSecret.getValue() != null ? clientSecret.getValue() : Config.clientSecret);

        PddDdkResourceUrlGenRequest request = new PddDdkResourceUrlGenRequest();
        request.setCustomParameters(null);
        request.setGenerateQqApp(false);
        request.setGenerateSchemaUrl(true);
        request.setGenerateWeApp(true);
        request.setPid(pid);
        request.setResourceType(39997);
        request.setUrl(null);
        PddDdkResourceUrlGenResponse response = null;
        try {
            response = client.syncInvoke(request);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return response;
    }


    @GetMapping("/getSubsidyProd")
    @ApiOperation("商品数据筛选通过筛选sort_type分页")
    public PddDdkGoodsSearchResponse getSubsidyProd(@RequestParam Integer sortType,
                                                        @RequestParam Integer page, @RequestParam Integer pageSize,@RequestParam String activityTags) {
        PddDdkGoodsSearchResponse response = null;
        try {
            //clientId
            CommonInfo clientId = commonRepository.findOne(23);
            CommonInfo clientSecret = commonRepository.findOne(24);
            PopClient client = new PopHttpClient(clientId.getValue() != null ? clientId.getValue() : Config.clientId, clientSecret.getValue() != null ? clientSecret.getValue() : Config.clientSecret);
            PddDdkGoodsSearchRequest request = new PddDdkGoodsSearchRequest();
            request.setPage(page);
            CommonInfo pdd = commonRepository.findOne(26);
            UserInfo userInfo = userRepository.getUserByPdd(pdd.getValue());
            String s1 = "{\"uid\":\"" + userInfo.getRelationId() + "\"}";
            List<Integer> integers = new ArrayList<>();
            String[] split = activityTags.split(",");
            for (String s : split) {
                Integer integer = Integer.valueOf(s);
                integers.add(integer);
            }
            request.setActivityTags(integers);
            request.setPid(userInfo.getPdd());
            request.setCustomParameters(s1);
            request.setPageSize(pageSize);
            request.setSortType(sortType);
            request.setWithCoupon(false);
            return client.syncInvoke(request);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
